home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple Developer Connection Student Program
/
ADC Tools Sampler CD Disk 3 1999.iso
/
Cool Demos, SDKs, & Tools
/
Demos⁄Tools⁄Offers
/
Eiffel for CW beta 3
/
EiffelS2
/
LIBRARY
/
MOTEL
/
Text.c
< prev
next >
Wrap
Text File
|
1999-05-27
|
10KB
|
501 lines
/*------------------------------------------------------------------*/
/* Eiffel/S II MacOS Runtime */
/*------------------------------------------------------------------*/
/* Author : Ian Joyner */
/* Release : 1.0 */
/* Date : Dec. 1997 */
/* Copyright : Ian Joyner */
/*------------------------------------------------------------------*/
#include <TextEdit.h>
#include <Eiffel2.h>
#include "MOTEL.h"
/********************************************************************/
/* */
/* TEXT EDIT */
/* */
/********************************************************************/
TEHandle platform_text_new_mono (INTEGER dleft, INTEGER dtop, INTEGER dright, INTEGER dbottom,
INTEGER vleft, INTEGER vtop, INTEGER vright, INTEGER vbottom)
{
Rect dest_rect;
Rect view_rect;
SetRect (&dest_rect, dleft, dtop, dright, dbottom);
SetRect (&view_rect, vleft, vtop, vright, vbottom);
return TENew (&dest_rect, &view_rect);
}
TEHandle platform_text_new_style (INTEGER dleft, INTEGER dtop, INTEGER dright, INTEGER dbottom,
INTEGER vleft, INTEGER vtop, INTEGER vright, INTEGER vbottom)
{
Rect dest_rect;
Rect view_rect;
TEHandle h;
SetRect (&dest_rect, dleft, dtop, dright, dbottom);
SetRect (&view_rect, vleft, vtop, vright, vbottom);
h = TEStyleNew (&dest_rect, &view_rect);
return h;
}
INTEGER platform_text_size ()
{
TERec p;
return (sizeof (p));
}
void platform_text_release (TEHandle h)
{
TEDispose (h);
}
void platform_text_activate (TEHandle h)
{
TEActivate (h);
}
void platform_text_deactivate (TEHandle h)
{
TEDeactivate (h);
}
void platform_text_key (TEHandle h, CHARACTER ch)
{
TEKey (ch, h);
}
void platform_text_set (TEHandle h, POINTER t, INTEGER length)
{
TESetText (t, length, h);
}
POINTER platform_text_get (TEHandle h)
{
return *TEGetText (h);
}
INTEGER platform_text_length (TEHandle h)
{
return (*h)->teLength;
}
POINTER platform_text_text (TEHandle h)
{
return *(*h)->hText;
}
INTEGER platform_text_line_count (TEHandle h)
{
return (*h)->nLines;
}
INTEGER platform_text_line (TEHandle h)
{
int i;
for (i=0; i < (*h)->nLines; i++)
if ((*h)->lineStarts [i] > (*h)->selStart)
return i - 1;
}
void platform_text_coord_dest_rect (TEHandle h, INTEGER *l, INTEGER *t, INTEGER *r, INTEGER *b)
{
*l = (*h)->destRect.left;
*t = (*h)->destRect.top;
*r = (*h)->destRect.right;
*b = (*h)->destRect.bottom;
}
void platform_text_coord_view_rect (TEHandle h, INTEGER *l, INTEGER *t, INTEGER *r, INTEGER *b)
{
*l = (*h)->viewRect.left;
*t = (*h)->viewRect.top;
*r = (*h)->viewRect.right;
*b = (*h)->viewRect.bottom;
}
void platform_text_set_select (TEHandle h, INTEGER sel_start, INTEGER sel_end)
{
TESetSelect (sel_start, sel_end, h);
}
void platform_text_go_to_line (TEHandle h, INTEGER n)
{
if (n > (*h)->nLines)
platform_text_set_select (h, (*h)->teLength, (*h)->teLength);
else
platform_text_set_select (h, (*h)->lineStarts [n], (*h)->lineStarts [n]);
}
void platform_text_go_to_line_end (TEHandle h, INTEGER n)
{
if (n >= (*h)->nLines)
platform_text_set_select (h, (*h)->teLength, (*h)->teLength);
else
platform_text_set_select (h, (*h)->lineStarts [n+1] - 1, (*h)->lineStarts [n+1] - 1);
}
void platform_text_set_style_handle (TEHandle h, TEStyleHandle t)
{
TESetStyleHandle (t, h);
}
TEStyleHandle platform_text_get_style_handle (TEHandle h)
{
return TEGetStyleHandle (h);
}
void platform_text_idle (TEHandle h)
{
TEIdle (h);
}
void platform_text_click (TEHandle h, INTEGER x, INTEGER y, BOOLEAN extend)
{
Point p;
SetPt (&p, x, y);
TEClick (p, extend, h);
}
INTEGER platform_text_sel_start (TEHandle h)
{
return ((**h).selStart);
}
INTEGER platform_text_sel_end (TEHandle h)
{
return ((**h).selEnd);
}
BOOLEAN platform_text_active (TEHandle h)
{
return ((**h).active);
}
void platform_text_align (TEHandle h, INTEGER alignment)
{
TESetAlignment (alignment, h);
}
void platform_text_update (TEHandle h, INTEGER l, INTEGER t, INTEGER r, INTEGER b)
{
Rect rc;
SetRect (&rc, l, t, r, b);
TEUpdate (&rc, h);
}
void platform_text_box (POINTER text, INTEGER length, INTEGER l, INTEGER t, INTEGER r, INTEGER b, INTEGER align)
{
Rect rc;
SetRect (&rc, l, t, r, b);
TETextBox (text, length, &rc, align);
}
void platform_text_set_view_rect (TEHandle h, INTEGER l, INTEGER t, INTEGER r, INTEGER b)
{
Rect rc;
SetRect (&rc, l, t, r, b);
(**h).viewRect = rc;
}
void platform_text_set_dest_rect (TEHandle h, INTEGER l, INTEGER t, INTEGER r, INTEGER b)
{
Rect rc;
SetRect (&rc, l, t, r, b);
(**h).destRect = rc;
}
void platform_text_recal (TEHandle h)
{
TECalText (h);
}
INTEGER platform_text_height (TEHandle h, INTEGER start, INTEGER end)
{
return TEGetHeight (end, start, h);
}
void platform_text_scroll (TEHandle h, INTEGER dh, INTEGER dv)
{
TEScroll (dh, dv, h);
}
void platform_text_scroll_limited (TEHandle h, INTEGER dh, INTEGER dv)
{
TEPinScroll (dh, dv, h);
}
void platform_text_scroll_enable (TEHandle h)
{
TEAutoView (true, h);
}
void platform_text_scroll_disable (TEHandle h)
{
TEAutoView (false, h);
}
void platform_text_selection_visible (TEHandle h)
{
TESelView (h);
}
void platform_text_delete (TEHandle h)
{
TEDelete (h);
}
void platform_text_insert (TEHandle h, POINTER text, INTEGER l)
{
TEInsert (text, l, h);
}
void platform_text_cut (TEHandle h)
{
TECut (h);
}
void platform_text_copy (TEHandle h)
{
TECopy (h);
}
void platform_text_paste (TEHandle h)
{
TEPaste (h);
}
void platform_text_style_paste (TEHandle h)
{
TEStylePaste (h);
}
void platform_text_to_scrap ()
{
OSErr err;
err = TEToScrap ();
}
void platform_text_from_scrap ()
{
OSErr err;
err = TEFromScrap ();
}
Handle platform_text_scrap_handle ()
{
return TEScrapHandle ();
}
INTEGER platform_text_scrap_length ()
{
return TEGetScrapLength ();
}
void platform_text_scrap_set_length (INTEGER new_size)
{
TESetScrapLength (new_size);
}
void platform_text_add_face (INTEGER *face, INTEGER new_face)
{
*face |= new_face;
}
void platform_text_remove_face (INTEGER *face, INTEGER old_face)
{
*face ^= old_face;
}
void platform_text_set_attributes (TEHandle h, INTEGER the_mode,
INTEGER the_font, INTEGER the_style, INTEGER the_size, INTEGER the_red, INTEGER the_green, INTEGER the_blue,
BOOLEAN redraw)
{
RGBColor c;
TextStyle t;
c.red = the_red;
c.green = the_green;
c.blue = the_blue;
t.tsFont = the_font;
t.tsFace = the_style;
t.tsSize = the_size;
t.tsColor = c;
TESetStyle (the_mode, &t, redraw, h);
}
void platform_text_replace_attributes (TEHandle h, INTEGER the_mode,
INTEGER old_font, INTEGER old_style, INTEGER old_size, INTEGER old_red, INTEGER old_green, INTEGER old_blue,
INTEGER new_font, INTEGER new_style, INTEGER new_size, INTEGER new_red, INTEGER new_green, INTEGER new_blue,
BOOLEAN redraw)
{
RGBColor old_c, new_c;
TextStyle old_t, new_t;
old_c.red = old_red;
old_c.green = old_green;
old_c.blue = old_blue;
old_t.tsFont = old_font;
old_t.tsFace = old_style;
old_t.tsSize = old_size;
old_t.tsColor = old_c;
new_c.red = new_red;
new_c.green = new_green;
new_c.blue = new_blue;
new_t.tsFont = new_font;
new_t.tsFace = new_style;
new_t.tsSize = new_size;
new_t.tsColor = new_c;
TEReplaceStyle (the_mode, &old_t, &new_t, redraw, h);
}
BOOLEAN platform_text_continuous_attributes (TEHandle h, INTEGER the_mode,
INTEGER the_font, INTEGER the_style, INTEGER the_size, INTEGER the_red, INTEGER the_green, INTEGER the_blue)
{
RGBColor c;
TextStyle t;
short m;
m = the_mode;
c.red = the_red;
c.green = the_green;
c.blue = the_blue;
t.tsFont = the_font;
t.tsFace = the_style;
t.tsSize = the_size;
t.tsColor = c;
return TEContinuousStyle (&m, &t, h);
}
void platform_text_style_insert (TEHandle h, POINTER text, INTEGER l, StScrpHandle sh)
{
TEStyleInsert (text, l, sh, h);
}
POINTER platform_text_style_get_scrap (TEHandle h)
{
TEGetStyleScrapHandle (h);
}
void platform_text_style_apply (TEHandle h, INTEGER s, INTEGER e, StScrpHandle sh, BOOLEAN redraw)
{
TEUseStyleScrap (s, e, sh, redraw, h);
}
void platform_text_style_count (TEHandle h, INTEGER s, INTEGER e)
{
TENumStyles (s, e, h);
}
INTEGER platform_text_offset (TEHandle h, INTEGER x, INTEGER y)
{
Point p;
SetPt (&p, x, y);
return TEGetOffset (p, h);
}
INTEGER platform_text_point (TEHandle h, INTEGER offset, INTEGER *x, INTEGER *y)
{
Point p;
p = TEGetPoint (offset, h);
*x = p.h;
*y = p.v;
}
INTEGER platform_text_feature_test (TEHandle h, INTEGER feature)
{
return TEFeatureFlag (feature, -1, h);
}
void platform_text_feature_set (TEHandle h, INTEGER feature)
{
TEFeatureFlag (feature, 1, h);
}
void platform_text_feature_reset (TEHandle h, INTEGER feature)
{
TEFeatureFlag (feature, 0, h);
}
/********************************************************************/
/* */
/* Font Calls */
/* */
/********************************************************************/
INTEGER platform_text_get_font_number (ConstStr255Param name)
{
short n;
Str255 scratch;
strcpy (scratch, name);
c2pstr ((char *)scratch);
GetFNum (scratch, &n);
return n;
}
POINTER platform_text_get_font_name (INTEGER num)
{
GetFontName (num, &scratch_string);
p2cstr ((char *)scratch_string);
return &scratch_string;
}
/********************************************************************/
/* */
/* Text Utilities */
/* */
/********************************************************************/
POINTER platform_string_get_ind (INTEGER list_id, INTEGER index)
{
GetIndString (&scratch_string, list_id, index);
p2cstr ((char *)scratch_string);
return &scratch_string;
}
POINTER platform_string_get (INTEGER string_id)
{
Handle sh = (char **)GetString (string_id); // don't know why we need (char **) cast??
strcpy (scratch_string, **sh);
DisposHandle (sh);
p2cstr ((char *)scratch_string);
return &scratch_string;
}